import request from '@/utils/request'

/**
 * Category
 */

export const getTypeId = (type) => {
  return request({
    url: '/whm/category/getType',
    method: 'get',
    params: {
      type: type
    }
  })
}
export const addCategory = (name, typeId, parentId) => {
  return request({
    url: '/whm/category/add',
    method: 'put',
    params: {
      name: name,
      typeId: typeId,
      parentId: parentId,
    }
  })
}
export const updateCategory = (id, name) => {
  return request({
    url: '/whm/category/update',
    method: 'put',
    params: {
      id: id,
      name: name,
    }
  })
}
export const removeCategory = (id) => {
  return request({
    url: '/whm/category/del' + `/${id}`,
    method: 'delete',
  })
}

export const getCategoryList = (typeId) => {
  return request({
    url: '/whm/category' + `/${typeId}`,
    method: 'get',
  })
}


/**
 * Product 物料/产品名录管理
 */
export const addProduct = (data) => {
  return request({
    url: '/whm/product/add',
    method: 'post',
    data
  })
}
export const getProductList = (categoryId, typeId) => {
  return request({
    url: '/whm/product/list',
    method: 'get',
    params: {
      categoryId: categoryId,
      typeId: typeId
    }
  })
}
export const delProduct = (id) => {
  return request({
    url: '/whm/product/del' + `/${id}`,
    method: 'delete',
  })
}
/** 
 * 库存管理
 */
export const getInventoryList = (data, isAll) => {
  return request({
    url: '/whm/inventory/list' + `/${isAll}`,
    method: 'post',
    data: {
      whId: data.whId,
      categoryId: data.categoryId,
      typeId: data.typeId,
      page: data.page,
      pageSize: data.pageSize,
    }
  })
}
export const getInventoryDetail = (id, page, pageSize) => {
  return request({
    url: '/whm/inventory' + `/${id}`,
    method: 'get',
    params: {
      page: page,
      pageSize: pageSize
    }
  })
}

export const getInboundDetail = (productId, whId, page, pageSize) => {
  return request({
    url: '/whm/inventory/inbound',
    method: 'get',
    params: {
      productId: productId,
      whId: whId,
      page: page,
      pageSize: pageSize
    }
  })
}

export const getOutboundDetail = (productId, whId, page, pageSize) => {
  return request({
    url: '/whm/inventory/outbound',
    method: 'get',
    params: {
      productId: productId,
      whId: whId,
      page: page,
      pageSize: pageSize
    }
  })
}

/** 入库单 */
export const addInbound = (whTypeId, data) => {
  return request({
    url: '/whm/inventory/inbound/add' + `/${whTypeId}`,
    method: 'post',
    data
  })
}

export const getInboundOrders = (data) => {
  return request({
    url: '/whm/inventory/inbound/list',
    method: 'post',
    data: data
  })
}

export const getInboundOrderAndDetail = (batchNo) => {
  return request({
    url: '/whm/inventory/inboundanddetail' + `/${batchNo}`,
    method: 'get'
  })
}